<?php

use eYaf\Logger;
use \Helper\ErrorCode;

/**
 * 当有未捕获的异常, 则控制流会流到这里
 */
class ErrorController extends Yaf\Controller_Abstract
{

    public function init() {
        Yaf\Dispatcher::getInstance()->disableView();
    }

    /**
     * 异常处理
     */
    public function errorAction()
    {

        $exception = $this->getRequest()->getException();
        try {
            throw $exception;
        } catch (Yaf\Exception\LoadFailed $e) {
            //加载失败
            Logger::getLogger()->logException($e);
        } catch (Yaf\Exception $e) {
            //其他错误
            Logger::getLogger()->logException($e);
        } catch (Exception $e) {
            Logger::getLogger()->logException($e);
        }

        $res = ['code' => ErrorCode::ERROR_SYSTEM, 'message'=>ErrorCode::getMsg(ErrorCode::ERROR_SYSTEM)];
        header('Content-Type: application/json;charset=utf-8');
        echo json_encode($res, JSON_UNESCAPED_UNICODE);
        exit;
    }
}